package com.motong.gongdan.util;

import com.motong.gongdan.util.page.Page;
import com.motong.gongdan.util.page.PageInfo;

import java.util.List;

/**
 * @author:fff
 * @time:2022/3/30
 */
public class PageUtil {
    public static PageInfo getNewPageInfo(Integer pageN, Integer limit, List<?> list){
        if(pageN==0){
            pageN = 1;
        }
        Page page = new Page(pageN,limit);
        int total = list.size();
        page.setTotal(total);
        int startIndex = (pageN - 1) * limit;
        int endIndex = Math.min(startIndex + limit,total);
        page.addAll(list.subList(startIndex,endIndex));
        PageInfo pageInfo = new PageInfo(page);
        return pageInfo;
    }
}
